package com.example.samples;

import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import com.example.R;

/**
 * Created with IntelliJ IDEA.
 * User: Andrei
 * Date: 8/8/12
 * Time: 9:45 PM
 * To change this template use File | Settings | File Templates.
 */
public class ExampleAnimationDynamic extends ListActivity {
    private Animation a;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.example_dynamic);
        String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
                "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
                "Linux", "OS/2" };
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                R.layout.row_layout, R.id.label, values);
        setListAdapter(adapter);


        a = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0,
                Animation.RELATIVE_TO_PARENT, 0,
                Animation.RELATIVE_TO_SELF, 0,
                Animation.ABSOLUTE, -300);
        a.setDuration(1000);
        a.setInterpolator(new DecelerateInterpolator());
        a.setFillAfter(true);
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        getListView().getChildAt(position).startAnimation(a);
    }
}